package com.example.demo.controller;


import com.example.demo.annotation.UserLoginToken;
import com.example.demo.entity.TbBlogEntity;
import com.example.demo.entity.TbMoodEntity;
import com.example.demo.entity.request.IdList;
import com.example.demo.entity.request.PushMoodEntity;
import com.example.demo.service.TbMoodService;
import com.example.demo.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


@Api("心情后台API")
@RestController
@RequestMapping("/admin/mood")
public class AdminMoodController {
    TbMoodService moodService;

    @Autowired
    public void setMoodService(TbMoodService moodService) {
        this.moodService = moodService;
    }

    @UserLoginToken
    @ApiOperation("发布心情语录")
    @ApiImplicitParam(name = "content", value = "内容")
    @PostMapping("pushMood")
    public Result pushMood(@RequestBody @Validated PushMoodEntity pushMoodEntity) {
        String content = pushMoodEntity.getContent();
        moodService.pushMood(content);
        return new Result(0, "success");
    }

    @ApiOperation("分页获取心情列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "index", value = "当前页"),
            @ApiImplicitParam(name = "size", value = "页大小")
    })
    @GetMapping("getMoodsByPage")
    public Result getMoodsByPage(Integer index, Integer size) {
        Map<String, Object> moods = moodService.getMoodsByPage(index, size);
        return new Result(0, "success", moods);
    }

    @UserLoginToken
    @ApiOperation("删除心情")
    @ApiImplicitParam(name = "ids")
    @PostMapping("deleteMoodById")
    public Result deleteMoodById(@RequestBody @Validated IdList idList) {
        moodService.deleteMoodById(idList.getIds());
        return new Result(0, "success");
    }


}
